package com.firefly.web.controller.admin.cms;


import com.firefly.dao.dto.cms.AdDto;
import com.firefly.dao.dto.cms.AdSearchDto;
import com.firefly.web.controller.admin.ConsoleApiRestController;
import com.firefly.dao.dto.CommonDto;
import com.firefly.dao.dto.cms.AdSortDto;
import com.firefly.dao.vo.CommonListVo;
import com.firefly.dao.vo.cms.AdVo;
import com.firefly.service.command.cms.AdCommand;
import com.firefly.service.query.cms.AdQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

/**
 * (Ads)表控制层
 *
 * @author makejava
 * @since 2022-08-02 08:57:42
 */
@ConsoleApiRestController("/ad")
public class AdController {
    private final AdQuery adQuery;
    private final AdCommand adCommand;

    @Autowired
    public AdController(AdQuery adQuery, AdCommand adCommand) {
        this.adQuery = adQuery;
        this.adCommand = adCommand;
    }

    @GetMapping("/list")
    public CommonListVo getAll(AdSearchDto request) {
        return adQuery.getList(request);
    }

    @GetMapping("/detail")
    public AdVo getDetail(@Validated(CommonDto.showDetail.class) CommonDto request) {
        return adQuery.detail(request.getDetailId());
    }

    @PostMapping("/create")
    public Boolean postCreate(@Validated(AdDto.create.class) AdDto request) {
        return adCommand.create(request);
    }

    @PostMapping("/update")
    public Boolean postUpdate(@Validated(AdDto.update.class) AdDto request) {
        return adCommand.update(request);
    }

    @PostMapping("/remove")
    public Boolean postRemove(@Validated(CommonDto.removeMultiple.class) CommonDto request) {
        return adCommand.removeByIds(request.detailIds);
    }

    @PostMapping("/sort")
    public Boolean postSort(@Validated AdSortDto request) {
        return adCommand.updateSort(request.getId(), request.getSort());
    }
}

